package com.SMP.controller.meet_room;

import com.SMP.model.Lessons;
import com.SMP.model.MeetPerson;
import com.SMP.model.Msg;
import com.SMP.service.class_room.LessonsService;
import com.SMP.service.meet_room.MeetPersonService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
public class MeetPersonController {
    @Autowired
    MeetPersonService meetPersonService;

    /**
     * @author TSY
    // * @param 查询参会人员
     */
    @RequestMapping("/selMeetPerson")
    @ResponseBody

    public Msg findMeetPerson(@RequestParam(value = "pn", defaultValue = "1") Integer pn){
        PageHelper.startPage(pn, 5);
        List<MeetPerson> meetPerson = meetPersonService.getAllMeetPerson();
        PageInfo page = new PageInfo(meetPerson, 5);
        return Msg.success().add("pageInfo", page);
    }
    /**
     * @author TSY
    // * @param 添加参会人员
     */
    @RequestMapping(value="/addMeetPer")
    @ResponseBody
    public Msg addMeetPerson(MeetPerson meetPerson){
        int a= meetPersonService.addMeetPerson(meetPerson);
        if (a==1) {
            return Msg.success();
        } else {
            return Msg.fail();
        }
    }
    /**
     * @author TSY
    // * @param 按照Id查询参会人员
     */
    @RequestMapping(value="/meetPerWithId")
    @ResponseBody
    public Msg getMeetPerWithId(@RequestParam(value="personId")String personId){
        MeetPerson meetPerson = meetPersonService.getMeetPerWithId(personId);
        return Msg.success().add("meetPersons", meetPerson);
    }
    /**
     * @author TSY
    // * @param 按照姓名查询参会人员
     */
    @RequestMapping(value="/meetPerWithName")
    @ResponseBody
    public Msg getMeetPerWithName(@RequestParam(value="personName")String personName){
        MeetPerson meetPerson = meetPersonService.getMeetPerWithName(personName);
        return Msg.success().add("meetPersons", meetPerson);
    }
    /**
     * @author TSY
    // * @param 修改参会人员
     */
    @ResponseBody
    @RequestMapping(value="/updMeetPerson")
    public Msg updateMeetPerson(MeetPerson meetPerson){
        int a=meetPersonService.updateMeetPerson(meetPerson);
        if (a==1) {
            return Msg.success();
        } else {
            return Msg.fail();
        }
    }
    /**
     * @author TSY
    // * @param 删除参会人员(假删)
     */
    @ResponseBody
    @RequestMapping(value="/deleteById")
    public Msg deleteMeetPer(@RequestParam(value="personId")String personId){
        int a=meetPersonService.deleteMeetPerson(personId);
        if (a==1) {
            return Msg.success();
        } else {
            return Msg.fail();
        }
    }
}

